<?php

/**
 * This is the model class for table "profile_field".
 *
 * The followings are the available columns in table 'profile_field':
 * @property string $name
 * @property string $label
 * @property string $type
 * @property integer $required
 * @property string $match
 * @property integer $email
 * @property integer $url
 * @property integer $numerical
 * @property string $in
 * @property integer $visible
 */
class ProfileField extends CActiveRecord
{
	const INVISIBLE = 0;
	const VISIBLE_ALL = 1;
	const VISIBLE_OWNER = 2;
	const VISIBLE_REGISTER = 3;

	public $dataLength;
	public $dataType;
	
	public function getVisibleTypes(){
		return array(
			self::VISIBLE_ALL=>'Visible all',
			self::INVISIBLE=>'In Visible',			
			self::VISIBLE_OWNER=>'Visible owner',
			self::VISIBLE_REGISTER=>'Visible register'
		);
	}
	public function getFieldTypes(){
		return array(
			'textField'=>'Text field',
			'textArea'=>'Text area',
			'checkBoxList'=>'Check boxes',
			'dropDownList'=>'Drop down list',
			'dropDownList'=>'Drop down list',
			'radioButtonList'=>'Radio buttons',
			'fileField'=>'Field field',
			'hiddenField'=>'Hidden field'
		);
	}
	public function getDataTypes(){
		return array(
			'INT'=>'INT',
			'VARCHAR'=>'VARCHAR',
			'TEXT'=>'TEXT',
			'DATE'=>'DATE',
			'NUMERIC'=>array(
				'TINYINT'=>'TINYINT',
				'SMALLINT'=>'SMALLINT',
				'MEDIUMINT'=>'MEDIUMINT',
				'BIGINT'=>'BIGINT',
				'DECIMAL'=>'DECIMAL',
				'FLOAT'=>'FLOAT',
				'DOUBLE'=>'DOUBLE',
				'SERIAL'=>'SERIAL'
			),
			'DATE and TIME'=>array(
				'DATE'=>'DATE',
				'DATETIME'=>'DATETIME',
				'TIMESTAMP'=>'TIMESTAMP',
				'TIME'=>'TIME',
				'YEAR'=>'YEAR'
			),
			'STRING'=>array(
				'CHAR'=>'CHAR',
				'VARCHAR'=>'VARCHAR',
				'TEXT'=>'TEXT',
				'LONGTEXT'=>'LONGTEXT',
				'ENUM'=>'ENUM'
			)
		);
	}
	/**
	 * Returns the static model of the specified AR class.
	 * @return ProfileField the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'profile_field';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, label, type', 'required'),
			array('required, email, url, numerical, visible', 'numerical', 'integerOnly'=>true),
			array('name', 'length', 'max'=>64),
			array('label', 'length', 'max'=>255),
			array('type', 'length', 'max'=>50),
			array('match, in', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('name, label, type, required, match, email, url, numerical, in, visible', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'name' => 'Name',
			'label' => 'Label',
			'type' => 'Type',
			'options' => 'Options',
			'default' => 'Default value',
			'required' => 'Required',
			'match' => 'Match',
			'email' => 'Email',
			'url' => 'Url',
			'numerical' => 'Numerical',
			'in' => 'In',
			'visible' => 'Visible',
			'dataLength'=>'Data length',
			'dataType'=>'Data type'
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('name',$this->name,true);
		$criteria->compare('label',$this->label,true);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('required',$this->required);
		$criteria->compare('match',$this->match,true);
		$criteria->compare('email',$this->email);
		$criteria->compare('url',$this->url);
		$criteria->compare('numerical',$this->numerical);
		$criteria->compare('in',$this->in,true);
		$criteria->compare('visible',$this->visible);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}